<template>
	<view class="shippingaddress">
		<view class="shippingaddress_top"></view>
		
		<view class="shippingaddress_main" >
			<view v-if="isshow" style="text-align: center;">
				<image src="../../static/iconShow/noOrder.png"></image>
			</view>
			<radio-group class="radio-group" >
				<label class="uni-list-cell uni-list-cell-pd"  v-for="(item, index) in listsss" :key="item.id">
					<view class="shippingaddress_main_a">
						<view class="shippingaddress_main_top" >
							<text class="text1">{{item.realName}}</text>
							<text class="text2">{{item.phone}}</text>
						</view>
						<view class="shippingaddress_main_zhong">
							<view>{{item.province}} {{item.city}} {{item.district}} {{item.detail}}</view>
							<view style="padding: 16rpx 0;"></view>
						</view>
						<view class="shippingaddress_main_bottom">
							<view class="shippingaddress_main_bottom_left" >
								<radio :value="String(item.isDefault)" color="#0EA970" @click="moren(item.id)" :checked="item.isDefault ==1"
									style="transform:scale(0.6)" />
								<!-- <view @click="xuanzhong(item)"> -->
								<view >
									<text v-if="item.isDefault==1">默认地址</text>
									<text v-if="item.isDefault==0">设为默认地址</text>
								</view>

							</view>
							<view class="shippingaddress_main_bottom_right">
								<text style="margin-right: 60rpx;" @click="redact(item.id)">编辑</text>
								<text @click="shippingdelete(item.id)">删除</text>
							</view>

						</view>
					</view>
				</label>
			</radio-group>
			<view class="shippingaddress_bottom_s" @click="site">
				新建地址
			</view>
		</view>

	</view>
</template>

<script>
	import homeServices from '../../service/homeService'
	export default {
		data() {
			return {
				checked: true,
				obj: true,
				ID: 1,
				
				current: 0,
				lists: [],
				listss: [],
				listsss: [],
				selected: [],
				limit: 10,
				page: 1,
				ids: '',
				isshow:false
			}
		},
		methods: {
			
			async customeraddress() {
				let params = {
					limit: this.limit,
					page: this.page
				}
				let res = await homeServices.customeraddress(params)
				this.listsss = res.data
				// console.log(res.data.length);
				if(res.data.length==0){
					this.isshow=true
				}else{
					this.isshow=false
				}

				console.log(this.listsss);
			},
			// 编辑
			redact(id) {
				uni.navigateTo({
					url: `/pagesB/redact/redact?id=${id}`
				})
			},


			// 删除
			 shippingdelete(id) {
				uni.showModal({
					title: '提示',
					content: '确认删除吗？',
					confirmText:'确定',
					cancelText:'取消',
					success: async res => {
						if (res.confirm) {
							this.ids = id
							let params = {
								id: this.ids
							}
							let res = await homeServices.shippingdelete(params)
							console.log(res)
							this.customeraddress()
						} else if (res.cancel) {
							return
						}
					}
							
				})
				
			},
			// 默认
			async moren(id) {
				console.log(id)
				this.ids = id

				let params = {
					id: id
				}
				let res = await homeServices.moren(params)
				console.log(res)
				this.listsss = []
				this.customeraddress()
			},
			// radioChange(evt) {
			// 	console.log("333333" + evt.detail.value)
			// 	for (let i = 0; i < this.listss.length; i++) {
			// 		if (this.listss[i].isDefault === evt.detail.value) {
			// 			this.current = i;
						
			// 			break;
			// 		}
			// 	}
				

			// },
			// xuanzhong(item) {
			// 	if (this.selected.indexOf(item) !== -1) {
			// 		console.log(this.selected.indexOf(item));
			// 		this.selected.splice(this.selected.indexOf(item), 1); //取消
			// 	} else {
			// 		this.selected.push(item); //选中添加到数组里

			// 		this.lists = item
			// 		// console.log(this.lists)
			// 		uni.navigateTo({
			// 			url: `/pagesA/purchase/purchase?lists=` + JSON.stringify(this.lists)
			// 		})
					
			// 	}
			// },
			site() {
				uni.navigateTo({
					url: '/pagesA/new/new'
				})
			},
			// shang() {
			// 	console.log(123)
				
			// 	uni.navigateBack({
			// 		delta: 1
			// 	})
			// }
		},
		onLoad() {
			
			// this.listsss = []

		},
		onShow() {
			this.customeraddress()
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/static/sass/shippingaddress.scss'
</style>
